﻿using System;

namespace test2
{
    interface Shape
    {
        double CalculateArea();
        bool JudgeLegal();
    }
    class Rectangle : Shape
    {
        public double length;
        public double width;
        public Rectangle(double length, double width)
        {
            this.length = length;
            this.width = width;
        }
        public double CalculateArea()
        {
            double area = length * width;
            return area;
        }

        public bool JudgeLegal()
        {
            if (length > 0 && width > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
    class Square : Shape
    {
        public double length;
        public Square(double length)
        {
            this.length = length;
        }
        public double CalculateArea()
        {
            double area = length * length;
            return area;
        }

        public bool JudgeLegal()
        {
            if (length > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
    class Triangle : Shape
    {
        public double a, b, c;
        public Triangle(double a, double b, double c)
        {
            this.a = a;
            this.b = b;
            this.c = c;
        }

        public double CalculateArea()
        {
            double s = (a + b + c) / 2;
            double area = Math.Sqrt(s * (s - a) * (s - b) * (s - c));
            return area;
        }

        public bool JudgeLegal()
        {
            if (a + b > c && a + c > b && b + c > a)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
    class ShapeTest
    {
        static void Main(string[] args)
        {
            Console.WriteLine("长方形：");
            Console.WriteLine("该长方形的长度：");
            int length = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("该长方形的宽度：");
            int width = Convert.ToInt32(Console.ReadLine());
            Rectangle rectangle = new Rectangle(length, width);
            Console.WriteLine("该长方形是否合法：" + rectangle.JudgeLegal());
            Console.WriteLine("该长方形的面积：" + rectangle.CalculateArea());
            Console.WriteLine("正方形：");
            Console.WriteLine("该正方形的边长：");
            int len = Convert.ToInt32(Console.ReadLine());
            Square square = new Square(len);
            Console.WriteLine("该正方形是否合法：" + square.JudgeLegal());
            Console.WriteLine("该正方形的面积：" + square.CalculateArea());
            Console.WriteLine("三角形：");
            Console.WriteLine("该三角形的三条边长：");
            int a = Convert.ToInt32(Console.ReadLine());
            int b = Convert.ToInt32(Console.ReadLine());
            int c = Convert.ToInt32(Console.ReadLine());
            Triangle triangle = new Triangle(a, b, c);
            Console.WriteLine("该三角形是否合法：" + triangle.JudgeLegal());
            Console.WriteLine("该三角形的面积：" + triangle.CalculateArea());
        }
    }
}
